﻿@model dai_hoc_tuong_lai.Areas.Admin.Models.CateNganhHocModel
@{  AjaxOptions ajaxOpts = new AjaxOptions
    {
        HttpMethod = "post",
         OnComplete = "completedAjaxRequest",
        OnBegin = "show_Loading",
    };
}

<script type="text/javascript">

    function completedAjaxRequest(obj) {

        var returnObj = eval('(' + obj.responseText + ')');

        $('#box-busy').fadeOut('medium', function () {
            $('#box-busy').css('display', 'none');
        });

        if (returnObj.Status == "success") {
            if (returnObj.Message != null) {
                makeSuccessHighlight(returnObj.Message);
            }
            else if (returnObj.RedirectUrl != null) {
                window.location.href = returnObj.RedirectUrl;
            }
        } else {
            makeErrorHighlight(returnObj.Message);
        }

        return false;
    }

    function makeErrorHighlight(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>Alert: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area");
        $highlight.delay(4000).fadeOut(500);
    }

    function makeSuccessHighlight(messageStr) {
        var $highlight = $("<div style='padding: 0.7em; margin-bottom:5px; width: inherit;'><p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span><strong>Success: </strong>" + messageStr + "</p></div>");
        $highlight.addClass("ui-state-highlight ui-corner-all");
        $highlight.prependTo(".warning-area");
        $highlight.delay(4000).fadeOut(500);
    }

    $(document).ready(function () {
        $("#tabasAddCategory").tabs();
        onlistCategory();
    });

    function onlistCategory() {
        var valueID = $("#ParentIdCode").val();
        var selectOn = false;
        $.getJSON("/Admin/NganhHoc/AllCategories", { selectedId: 0 },
            function (carData) {
                var select = $("#selectCate");
                select.empty();
                $.each(carData, function (index, itemData) {
                    if (itemData.Value == valueID)
                        selectOn = true;
                    else
                        selectOn = false;
                    select.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text,
                        selected: selectOn
                    }));
                });
            });

    }

    function onchangeselectCate() {
        var value = $("#selectCate").val();
        $("#ParentIdCode").val(value);
    }
    
</script>
@using (Ajax.BeginForm("AddOrUpdateCate", "NganhHoc", null, ajaxOpts, new { enctype = "multipart/form-data" }))
{
    <div class="section-header">
        <dl class="submit">
            <img class="NFButtonLeft" src="img/0.png" style="border: 0" />
            <input type="submit" name="submit" id="submit" value="Submit" class="NFButton">
            <img src="img/0.png" class="NFButtonRight" style="border: 0" />
        </dl>
    </div>
    <div class="warning-area">
    </div>
    <div id="tabasAddCategory">
        <ul>
            <li><a href="#tabs-1">Chi tiết</a></li>
            <li><a href="#tabs-2">Seo</a></li>
        </ul>
        <div id="tabs-1">
            <table>
                <tr>
                    <td colspan="2">
                        @Html.HiddenFor(model => model.Id, new { id = "Id" })
                        @Html.HiddenFor(model => model.DateCreate)
                        @Html.HiddenFor(model => model.NgayTao)
                         @Html.HiddenFor(model => model.ParentId, new { id = "ParentIdCode" })
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.LabelFor(model => model.ParentId, "Chuyên mục cha"):
                    </td>
                    <td class="adminData">
                        <select id="selectCate" onchange="onchangeselectCate();" class="listCate" style="width: 400px;">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.LabelFor(model => model.Name, "Tên Chuyên mục"):
                    </td>
                    <td class="adminData">
                        @Html.TextBoxFor(model => Model.Name, new { @style = "width:500px" })
                        @Html.ValidationMessageFor(model => model.Name)
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        @Html.LabelFor(model => model.Mota, "Mô tả"):
                    </td>
                    <td class="adminData">
                        @Html.TextAreaFor(model => Model.Mota, new { @style = "width:500px", @rows="8", cols="8" })
                        @Html.ValidationMessageFor(model => model.Mota)
                    </td>
                </tr>
            </table>
        </div>
        <div id="tabs-2">
            <table>
            <tr>
                <td class="adminTitle">
                    @Html.LabelFor(model => model.KeyTitle, "Meta Title"):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => Model.KeyTitle, new { rows = "3", cols = "50" })
                    @Html.ValidationMessageFor(model => model.KeyTitle)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.LabelFor(model => model.Keyword, "Meta Keywords"):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => Model.Keyword, new { rows = "6", cols = "50" })
                    @Html.ValidationMessageFor(model => model.Keyword)
                </td>
            </tr>
            <tr>
                <td class="adminTitle">
                    @Html.LabelFor(model => model.Description, "Meta Description"):
                </td>
                <td class="adminData">
                    @Html.TextAreaFor(model => Model.Description, new { rows = "10", cols = "50" })
                    @Html.ValidationMessageFor(model => model.Description)
                </td>
            </tr>
    </table>
        </div>
    </div>
}
